﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Red.Toolkit.EngineLogsViewer.Data;

namespace Red.Toolkit.EngineLogsViewer.Visualization
{
    /// <summary>
    /// Interaction logic for LogGroup.xaml
    /// </summary>
    public partial class LogGroup : UserControl
    {
        public LogGroup()
        {
            InitializeComponent();
        }

        private void RedToggleButton_Checked( object sender, RoutedEventArgs e )
        {
            _header.Visibility = Visibility.Visible;
            _header.Text = ( (EngineLogGroupEntry)DataContext ).InternalLogEntries[0].Text;
            Height = _header.Height + _mainPanel.Margin.Bottom + _mainPanel.Margin.Top;
            _logEntries.Visibility = Visibility.Collapsed;
        }

        private void _openCloseButton_Unchecked( object sender, RoutedEventArgs e )
        {
            _header.Visibility = Visibility.Collapsed;
            Height = double.NaN;
            _logEntries.Visibility = Visibility.Visible;
        }

        private static bool UserFilter( object item )
        {
            EngineLogAbstractEntry e = (EngineLogAbstractEntry)item;
            return e.IsCategoryVisible && e.IsTextVisible && e.IsSeverityVisible && e.IsThreadIdVisible;
        }

        private void UserControl_Loaded( object sender, RoutedEventArgs e )
        {
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView( _logEntries.ItemsSource );
            view.Filter = UserFilter;
        }
    }
}
